Skip to content

Make loaded single-segment signal modes explicit - #756

Merged
tompollard merged 3 commits into
mainfrom
explicit-single-signal-values
Nov 28, 2026
Merged

tompollard merged 3 commits into
mainfrom
explicit-single-signal-values

Conversation

@tompollard

@tompollard tompollard commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Represent the four single-segment read modes explicitly at the boundary where
loaded values are assigned to a Record: physical or digital, and uniform or
expanded. The private _LoadedSignalValues checks the value layout and numeric
type, then fills the matching legacy signal field and clears the other three.
Uniform arrays must match (sig_len, n_sig); expanded channels must have
sig_len * samps_per_frame samples.

The existing in-place digital-to-physical conversion remains in use, so this
does not add a second full signal array during conversion. Public Record
fields and read options stay the same. This is an initial internal step for
#745, not a new public signal API.

Verification

  • Added tests for all four modes on a multi-frequency record, including
    shapes, dtypes, and which public field is populated.
  • Added tests for skewed missing samples converting to NaN in uniform and
    expanded physical reads.
  • Added tests rejecting incorrect uniform and expanded signal sizes.
  • Offline suite: 912 passed, 4 skipped, 21 deselected (MPLBACKEND=Agg).
  • Sphinx HTML build with warnings as errors passed; Ruff check and format
    check passed.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new _LoadedSignalValues.set_on_record checks dimensions and dtype, but it does not check that the values match the record's shape. For example, a (3, 1) digital array is accepted when record.n_sig == 2, and an expanded array of 2 samples is accepted when sig_len == 3 and samps_per_frame == [2] require 6. Both leave the Record internally inconsistent even though this helper is described as validating the loaded layout (src/wfdb/io/record.py:2400-2419). Please check the uniform shape against (sig_len, n_sig) and each expanded channel length against its frame count, or narrow the helper's stated validation contract.

I did not reproduce a failure in the current read paths. The full offline suite passed (910 passed, 4 skipped, 21 deselected).

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, you're right. I added the missing size checks in b33e49b. Uniform
values now have to match (sig_len, n_sig), and each expanded channel must
contain sig_len * samps_per_frame samples. I added tests for both mismatches.

The full offline suite passes: 912 passed, 4 skipped. Ruff checks pass too.

@tompollard tompollard left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added size checks address my earlier concern. The two malformed layouts I raised now fail before assignment, and the full offline suite passes (912 passed, 4 skipped, 21 deselected). I found no remaining correctness issue.

One small readability suggestion in _record_from_single_segment_read: the adjacent if read.physical: blocks can be combined so conversion and selection of the physical signal field happen in the same branch. They do different work, so the repetition is not a behavior bug. The current code has only one dac call; the longer call shown in the diff was removed.

@tompollard

Copy link
Copy Markdown
Member Author

Thanks, I combined the physical conversion and field selection in the same
branch in e3e440b. The focused signal-mode tests pass (8 passed), and Ruff
check and format pass.

@tompollard
tompollard merged commit f7bf762 into main Nov 28, 2026
19 checks passed
@tompollard
tompollard deleted the explicit-single-signal-values branch November 28, 2026 03:29
tompollard added a commit that referenced this pull request Nov 28, 2026
## Summary

Use the same private loaded-value mode check for records flattened from
multiple segments as for single-segment reads. It checks that the
combined
values match the physical/digital and uniform/expanded mode and the
resulting
record shape before assigning the public signal field.

This extends #756 toward #745. The `Record` API and output values stay
the
same. Segment-preserving reads already use the single-segment path for
each
loaded segment.

## Verification

- Added tests for all four flattened modes across a segment boundary.
- Offline suite: 916 passed, 4 skipped, 21 deselected
(`MPLBACKEND=Agg`).
- Ruff check and format check passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant